package com.jiuyun.service.Impl;

import com.jiuyun.dao.ClassesDao;
import com.jiuyun.dao.impl.ClassesDaoImpl;
import com.jiuyun.entity.HomeWork;
import com.jiuyun.entity.Student;
import com.jiuyun.service.ClassService;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;

public class ClassServiceImpl implements ClassService {

    ClassesDao classesDao = new ClassesDaoImpl();

    @Override
    public HashMap<String, int[]> homework(int classid, int year, int month) throws SQLException {
        HashMap<String,int[]> info = new HashMap<String, int[]>();
       int days[] = {30,28,31,30,31,30,31,31,30,31,30,31};
       int num = days[month-1];  //本月天数
       if (year%4==0 && year%100!=0 ||year%400==0){
           days[1]= 29;  //闰年29天
        }
        //所有学生
        List<Student> stus = classesDao.getstud(classid);
        //没做作业的列表
        List<HomeWork> works = classesDao.homework(classid,year,month);
        System.out.println(works);
        for (Student s : stus){
            info.put(s.getStname(),new  int[num]);
        }

        for (HomeWork h : works){
            String stname = h.getStname();
            System.out.println(stname);
            int t = h.getCtime().getDate();
            System.out.println(t);
            int rq[] = info.get(stname);
            rq[t-1] =1;  //没做的标志

        }
        return info;
    }
}
